﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace $safeprojectname$.Project.OData
{
    [TypeConverter(typeof(ODataFilterTypeConverter))]
    public class OldDataFilter
    {
        public virtual string Filter { get; set; }
        public virtual string OrderBy { get; set; }
        public virtual string Top { get; set; }
        public virtual string Skip { get; set; }
    }

    public class ODataFilterTypeConverter : TypeConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            if (sourceType == typeof(string))
            {
                return true;
            }
            return base.CanConvertFrom(context, sourceType);
        }

        public override object ConvertFrom(ITypeDescriptorContext context,
           System.Globalization.CultureInfo culture, object value)
        {
            if (value is string)
            {
                return new OldDataFilter()
                {
                    Filter = "it is working",
                    Skip = value.ToString(),
                };
            }

            return base.ConvertFrom(context, culture, value);
        }
    }
}
